<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业14</title>
    <script>
        /*
        用户输入一个三位数，弹出各个数位的和
        */

        var num = prompt("请输入一个三位数字：");

        if (num.length != 3){
            alert("输入数字的位数不对");
            throw Error;
        }
        
        var numInt = parseInt(num);

        if (isNaN(numInt)){
            alert("输入有误");
        }else{
            numBai = parseInt(numInt/100);
            numShi = parseInt(numInt/10)%10;
            numGe = numInt%10;

            var sum =numBai+numShi+numGe;

            alert("输入数字的各个数位相加的和是："+sum);
        }


    </script>
</head>
<body>
    
</body>
</html>